<?php
date_default_timezone_set('Asia/Shanghai');
error_reporting(E_ALL);
ob_start('ob_gzhandler');

define('PROJECT_ROOT', dirname(__DIR__));
define('APP_ROOT',     PROJECT_ROOT);
define('FPS_ROOT',     APP_ROOT . '/fps');
define('FPS_PROJECT',  'app');
define('FPS_PUBLIC_MODULES', '/login:/cron:/version');
define('FPS_VIEW_DEFAULT_LAYOUT', 'app');
define('FPS_WITH_SESSION', false);

// define('FPS_DB_COUNTER_TABLE', 'identitycounters');
// define('FPS_DB_COUNTER_KEY', 'name');
// define('FPS_DB_COUNTER_VALUE', 'value');

$conf_file = false;
if (isset($_SERVER["FPS_CONFIG_ROOT"])) {
	$conf_file = $_SERVER["FPS_CONFIG_ROOT"] . '/config.php';
	if (!file_exists($conf_file)) {
		$conf_file = false;
	}
}
if (!$conf_file) {
	$conf_file = PROJECT_ROOT . '/conf/config.php';
}

require_once($conf_file);
require_once(FPS_ROOT . '/core.php');
require_once(FPS_ROOT . '/json.php');
require_once(FPS_ROOT . '/view.php');
require_once(APP_ROOT . '/libs/constant.php');
require_once(APP_ROOT . '/libs/common.php');
require_once(APP_ROOT . '/libs/cache.php');

function fps_on_login() {
    json_out(500, 'Need Login');
}

function show_message($message, $url = 'javascript:window.history.go(-1)') {
	fpsView::render('message', array('url' => $url, 'message' => $message));
	exit;
}

// set default fpsView vars
fpsView::set(fps_config('SITE_LANG_TEXT'));

if (fps_run() === false) {
	json_out(404, 'uri not found');
}